package com.scgl.order.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.scgl.order.domain.ScglPlan;
import com.scgl.order.service.IScglPlanService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 关联生产计划Controller
 *
 * @author ruoyi
 * @date 2024-10-30
 */
@RestController
@RequestMapping("/plan")
public class ScglPlanController extends BaseController
{
    @Autowired
    private IScglPlanService scglPlanService;

    /**
     * 查询关联生产计划列表
     */
    @RequiresPermissions("order:plan:list")
    @GetMapping("/list")
    public TableDataInfo list(ScglPlan scglPlan)
    {
        startPage();
        List<ScglPlan> list = scglPlanService.selectScglPlanList(scglPlan);
        return getDataTable(list);
    }

    /**
     * 导出关联生产计划列表
     */
    @RequiresPermissions("order:plan:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScglPlan scglPlan)
    {
        List<ScglPlan> list = scglPlanService.selectScglPlanList(scglPlan);
        ExcelUtil<ScglPlan> util = new ExcelUtil<ScglPlan>(ScglPlan.class);
        util.exportExcel(response, list, "关联生产计划数据");
    }

    /**
     * 获取关联生产计划详细信息
     */
    @RequiresPermissions("order:plan:query")
    @GetMapping(value = "/{planId}")
    public AjaxResult getInfo(@PathVariable("planId") Long planId)
    {
        return success(scglPlanService.selectScglPlanByPlanId(planId));
    }

    /**
     * 新增关联生产计划
     */
    @RequiresPermissions("order:plan:add")
    @Log(title = "关联生产计划新增", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScglPlan scglPlan)
    {
        return toAjax(scglPlanService.insertScglPlan(scglPlan));
    }

    /**
     * 修改关联生产计划
     */
    @RequiresPermissions("order:plan:edit")
    @Log(title = "关联生产计划修改", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScglPlan scglPlan)
    {
        return toAjax(scglPlanService.updateScglPlan(scglPlan));
    }

    /**
     * 删除关联生产计划
     */
    @RequiresPermissions("order:plan:remove")
    @Log(title = "关联生产计划删除", businessType = BusinessType.DELETE)
	@DeleteMapping("/{planIds}")
    public AjaxResult remove(@PathVariable Long[] planIds)
    {
        return toAjax(scglPlanService.deleteScglPlanByPlanIds(planIds));
    }
}
